/**
 * 班级管理初始化
 */
var Examinee = {
    id: "ExamineeTable",	//表格id
    seItem: null,		//选中的条目
    table: null,
    layerIndex: -1
};

/**
 * 初始化表格的列
 */
Examinee.initColumn = function () {
    return [
            {title: 'id', field: 'id', visible: false, align: 'center', valign: 'middle'},
            {title: '准考证号', field: 'exam_card_number', visible: true, align: 'center', valign: 'middle'},
            {title: '姓名', field: 'student_name', visible: true, align: 'center', valign: 'middle'},
            {title: '所属学校', field: 'school_name', visible: true, align: 'center', valign: 'middle'},
            {title: '学校代码', field: 'school_code', visible: true, align: 'center', valign: 'middle'},
            {title: '所在班级', field: 'senoir_class_name', visible: true, align: 'center', valign: 'middle'},
            {title: '填报状态', field: 'write_status', visible: true, align: 'center', valign: 'middle'},
            {title: '确认状态', field: 'confirm_status', visible: true, align: 'center', valign: 'middle'},
            {title: '操作', field: 'caoz', visible: true, align: 'center', valign: 'middle',formatter: function (value, row, index) { return '<a href="javaScript:void(0);" onclick=Examinee.item("'+row.id+'")>详情信息</a>'}}
    ];
};

/**
 * 检查是否选中
 */
Examinee.check = function () {
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if(selected.length == 0){
        Feng.info("请至少选中表格中的某一记录！");
        return false;
    }else{
    	Examinee.seItem = selected;
        return true;
    }
};

/**
 * 打开查看班级详情
 */
Examinee.item = function (id) {
    var index = layer.open({
        type: 2,
        title: '志愿详情',
        area: ['85%', '85%'], //宽高
        fix: false, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/seniorWish/examineeItem?id='+id
    });
    this.layerIndex = index;
};


/**
 * 重置密码
 */
Examinee.changePwd = function () {
	if (this.check()) {
    	var operation = function(){
    	    //使用单选
          // var examineeIds="";
          // for(var i=0;i<Examinee.seItem.length;i++){
        	//   examineeIds+=Examinee.seItem[i].id+",";
          // }
	      var ajax = new $ax(Feng.ctxPath + "/seniorWish/changePwd", function (data) {
	            Feng.success("重置登录密码成功,密码为出生年月日!");
	            Examinee.table.refresh();
	        }, function (data) {
	            Feng.error("重置登录密码失败!" + data.responseJSON.message + "!");
	        });
	        ajax.set("examineeId",Examinee.seItem[0].id);
	        ajax.start();
    	 };
    	 Feng.confirm("确认重置登录密码？",operation);
    }
};

/**
 * 重置状态
 */
Examinee.changeSatus = function () {
	if (this.check()) {
    	var operation = function(){
    	    //使用单选
             // var examineeIds="";
             // for(var i=0;i<Examinee.seItem.length;i++){
           	//     examineeIds+=Examinee.seItem[i].id+",";
             // }
	        var ajax = new $ax(Feng.ctxPath + "/seniorWish/changeSatus", function (data) {
	            Feng.success("重置志愿状态成功!");
	            Examinee.table.refresh();
	        }, function (data) {
	            Feng.error("重置志愿状态失败!" + data.responseJSON.message + "!");
	        });
	        ajax.set("examineeId",Examinee.seItem[0].id);
	        ajax.start();
    	 };
    	 Feng.confirm("确认重置志愿状态？",operation);
    }
};

/**
 * 获取shoolId
 */
Examinee.getSchoolId=function(schoolSelectId){
	return {
		schoolId:$("#"+schoolSelectId).select2("val")
	}
}

$('#seniorSchoolId').on('select2:select', function (e) {
	$("#seniorClassId").val("").trigger("change");
});

Examinee.resetSearch = function () {
    $("#seniorSchoolId").val("").trigger("change");
    $("#seniorClassId").val("").trigger("change");
    $("#examCardNumber").val("");
    $("#confirmStatus").val("").trigger("change");
    Examinee.search();
}

/**
 * 查询班级列表
 */
Examinee.search = function () {
    var queryData = {};
    queryData['seniorSchoolId'] = $("#seniorSchoolId").val();
    queryData['seniorClassId'] = $("#seniorClassId").val();
    queryData['examCardNumber'] = $("#examCardNumber").val();
    queryData['confirmStatus'] = $("#confirmStatus").val();
    Examinee.table.refresh({query: queryData});
};

$(function () {
    var defaultColumns = Examinee.initColumn();
    var table = new BSTable(Examinee.id, "/seniorWish/examineeList", defaultColumns);
    Examinee.table = table.init();
});
